$(function(){
   
    //获取编辑的数据在本地存储中
    var editAddress = JSON.parse(localStorage.getItem("editAddress"));
    console.log(editAddress);
    //将获取的本地存储的数据渲染到表单中
    // console.log(id);
    var username = $("#username").val(editAddress.recipients);//收货人
    var code = $("#code").val(editAddress.postCode);
    var city = $("#city").val(editAddress.address);
    var adress = $("#adress").val(editAddress.addressDetail);
    
    
    //修改地址
    $("#modify-btn").on("click",function(){
        //获取修改后的表单内容
        var id = editAddress.id;
        var recipients = $("#username").val();//收货人
        var postcode = $("#code").val();
        var address = $("#city").val();
        var addressDetail = $("#adress").val();
        // console.log(addressDetail);
        // return;
        $.ajax({
            type:"post",
            url:"/address/updateAddress",
            data:{
                "id":id,
                "recipients":recipients,
                "postcode":postcode,
                "address":address,
                "addressDetail":addressDetail
            },
            success:function(res){
                // console.log(res);
                //修改成功
                if(res.success){
                    //删除本地存储的数据
                    localStorage.removeItem("editAddress");
                    location.href = "address.html";
                }
            }
        });
    });
});